package com.example.kcb;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

public class HorizontalLinesView extends View {
    private Paint paint;
    private int lineHeight;
    private int lineSpacing;

    public HorizontalLinesView(Context context, int lineSpacingDp, int lineHeightDp) {
        super(context);
        paint = new Paint();
        paint.setColor(Color.parseColor("#E0E0E0")); // 分割线颜色
        paint.setStrokeWidth(dpToPx(lineHeightDp));

        this.lineHeight = dpToPx(lineHeightDp);
        this.lineSpacing = dpToPx(lineSpacingDp);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width = getWidth();
        int height = getHeight();

        for (int y = lineSpacing; y < height + lineSpacing; y += lineSpacing) {
            canvas.drawLine(0, y, width, y, paint);
        }
    }

    private int dpToPx(int dp) {
        return (int) (dp * getResources().getDisplayMetrics().density);
    }
}
